//
//  AppDelegate.m
//  ExploreWorld
//
//  Created by dlios on 15/7/13.
//  Copyright (c) 2015年 chenlin. All rights reserved.
//

#import "AppDelegate.h"
#import "NewsViewController.h"
#import "ReadViewController.h"
#import "SetViewController.h"
#import "VideoViewController.h"
#import "SetViewController.h"
#import "MyTabBar.h"
#import "Header.h"
#import "UMSocial.h"
#import "UMSocialQQHandler.h"
#import "UMSocialSinaSSOHandler.h"
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"


@interface AppDelegate () <UITabBarControllerDelegate, UIApplicationDelegate>

@property (strong, nonatomic) SetViewController *setController;
@property (strong, nonatomic) UINavigationController *mainNavigationController;


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
#pragma mark - 友盟appkey
//    [UMSocialData setAppKey:@"55ac463267e58ec672002c87"];

#pragma mark - share-sdk
    [ShareSDK registerApp:@"8f2478802a92"];//字符串api20为您的ShareSDK的AppKey
    
    //添加新浪微博应用 注册网址 http://open.weibo.com
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台 （注意：2个方法只用写其中一个就可以）
    [ShareSDK  connectSinaWeiboWithAppKey:@"568898243"
                                appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                              redirectUri:@"http://www.sharesdk.cn"
                              weiboSDKCls:[WeiboSDK class]];
    
    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
    [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                  appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                redirectUri:@"http://www.sharesdk.cn"
                                   wbApiCls:[WeiboApi class]];
    
    
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"100371282"
                           appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    //添加QQ应用  注册网址  http://mobile.qq.com/api/
    [ShareSDK connectQQWithQZoneAppKey:@"100371282"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
    
    
    //添加豆瓣应用  注册网址 http://developers.douban.com
    [ShareSDK connectDoubanWithAppKey:@"07d08fbfc1210e931771af3f43632bb9"
                            appSecret:@"e32896161e72be91"
                          redirectUri:@"http://dev.kumoway.com/braininference/infos.php"];
    
    
    
    
    //    self.title = @"天下事";
    [self.mainNavigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica-Bold" size:20], NSFontAttributeName, nil]];
    self.mainNavigationController.title = @"天下事";
    
    
    self.window = [[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]autorelease];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    
    
    
    [self.window makeKeyAndVisible];
    
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:19 / 255.0 green:158 / 255.0 blue:238 / 255.0 alpha:1]];
    
    
    // 创建视图控制器
    NewsViewController *oneVC = [[[NewsViewController alloc]init]autorelease];
    oneVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"阅读" image:[UIImage imageNamed:@"1.png"] tag:1000]autorelease];
    
    // 创建导航
    
    UINavigationController *navi = [[[UINavigationController alloc] initWithRootViewController:oneVC]autorelease];
    // 第二个标签
    ReadViewController *twoVC = [[[ReadViewController alloc] init]autorelease];
    UINavigationController *navi2 = [[[UINavigationController alloc] initWithRootViewController:twoVC]autorelease];
    twoVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"阅读" image:[UIImage imageNamed:@"2.png"] tag:2000]autorelease];
    
    // 第三个标签
    VideoViewController *threeVC = [[[VideoViewController alloc] init]autorelease];
    UINavigationController *navi3 = [[[UINavigationController alloc]initWithRootViewController:threeVC]autorelease];
    threeVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"视听" image:[[UIImage imageNamed:@"3.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:3000]autorelease];
    // 第四个标签
    SetViewController *fourVC = [[[SetViewController alloc] init]autorelease];
    UINavigationController *navi4 = [[[UINavigationController alloc]initWithRootViewController:fourVC]autorelease];
    fourVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"4.png"] tag:4000]autorelease];
    
    
    // 创建标签控制器
    UITabBarController *tabBar = [[[UITabBarController alloc] init]autorelease];
    // 设置需要被 标签控制器管理的 控制器
    tabBar.viewControllers = @[navi, navi2, navi3, navi4,];
    // 设置tabBar不透明
    tabBar.tabBar.translucent = NO;
    // 设置代理人
    tabBar.delegate = self;
    // 把标签控制器 设置为根视图控制器
    self.window.rootViewController = tabBar;
    
    MyTabBar *myTabBar = [[[MyTabBar alloc] init] autorelease];
    myTabBar.viewControllers = @[navi, navi2, navi3, navi4];
    myTabBar.delegate = self;
    self.window.rootViewController = myTabBar;

#pragma mark - 友盟
//#pragma mark - 分享
//    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"55ac463267e58ec672002c87" url:@"http://www.umeng.com/social"];
//    
//    
//#pragma mark - sina 回调地址
//    //打开新浪微博的SSO开关，设置新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。若在新浪后台设置我们的回调地址，“http://sns.whalecloud.com/sina2/callback”，这里可以传nil
//    [UMSocialSinaSSOHandler openNewSinaSSOWithRedirectURL:@"http://weibo.com/2495565181/profile?topnav=1&wvr=6"];

    return YES;
}


#pragma mark - 友盟
//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
//{
//    return  [UMSocialSnsService handleOpenURL:url];
//}
//
//- (BOOL)application:(UIApplication *)application
//            openURL:(NSURL *)url
//  sourceApplication:(NSString *)sourceApplication
//         annotation:(id)annotation
//{
//    return  [UMSocialSnsService handleOpenURL:url];
//}






- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
